#include "stdafx.h"
#include "List.h"

const int MAXHVAL = 1000;

//////////////////////////////////////////////////////////////////////////

int _tmain()
{
	list *hashtable[MAXHVAL] = {};
	for (int iter_init = 0; iter_init < MAXHVAL; iter_init++) {
		hashtable[iter_init] = list_construct();
	}




	for (int iter_delete = 0; iter_delete < MAXHVAL; iter_delete++) {
		list_destruct(hashtable[iter_delete]);
	}
	DPUTCLOSURE;
	return 0;
}

//////////////////////////////////////////////////////////////////////////

unsigned long hash(const char plaintext[])
{
	assert(("Hash() has received an input string", plaintext != NULL));

	unsigned long out = 0, currpos = 0;
	while (plaintext[currpos] != '/0') {
		currpos++;
		out += plaintext[currpos];
	}
	out = (out / currpos) % MAXHVAL;
	return out;
}

void add_to_hash(char keytoadd[], list **htable)
{
	assert(("Add_to_hash has received a non-null Htable", htable != NULL));

	unsigned long hashval = hash(keytoadd);
	list_add(keytoadd, htable[hashval]);
}

elem* find_in_hash(char keytofind[], list **htable)
{
	assert(("Find_in_hash has received a non-null Htable", htable != NULL));
	
	elem* outelem = NULL;
	for (int iter_find = 0; iter_find < MAXHVAL; iter_find++) {
		outelem = list_find(keytofind, htable[iter_find]);
	}

	return outelem;
}